﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BusinessForm.aspx.cs"
    Inherits="FantastPlatform.Community.UI.BusinessForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var bf = new FantastPlatform.UI.BusinessForm({
            renderTo: 'bf_div',
            Id: '<%=GetId() %>',
            url: '../Service/BusinessService.aspx?Action=Add',           
            tbar: [{
                text: '保存',
                iconCls: 'save',
                handler: function () {
                    if (typeof (bg) == 'undefined') {
                        submitPanelJson(bf, currtWind, null);
                    } else {
                        submitPanelJson(bf, currtWind, bg);
                    } 
                }
            }, '-', {
                text: '重置',
                iconCls: 'cancel',
                handler: function () { bf.form.reset(); }
            }]
        })
        function submitPanelJson(form, sender, grid, fn, data) {
            if (form.form.isValid()) {
                var myMask = new Ext.LoadMask(sender.getEl(), {
                    msg: "正在保存数据,请稍候...."
                });
                var placeType = form.form.findField('PlaceType').getValue();
                var purPose = form.form.findField('Purpose').getValue();
                var policeStation = form.form.getValues().Organization;
                var responsibilityArea = form.form.getValues().ResponsibilityArea;
                var street = form.form.getValues().StreetId;

                var dataStr = '{';
                if (form.form.getValues().Id == undefined) {
                    dataStr += '"Id":0,';
                } else {
                    dataStr += '"Id":' + form.form.getValues().Id + ',';
                }
                dataStr += '"Name":"' + form.form.getValues().Name + '",';
                dataStr += '"Address":"' + form.form.getValues().Address + '",';
                dataStr += '"Description":"' + form.form.getValues().Description + '",';
                dataStr += '"Range":"' + form.form.getValues().Range + '",';
                dataStr += '"CreateDate":"' + form.form.getValues().CreateDate + '",';
                dataStr += '"Enable":"' + form.form.getValues().Enable + '"';
                //            dataStr += '"Owner":' + form.form.getValues().Owner[0] + ',';
                //            dataStr += '"Leader":"' + form.form.getValues().Leader[0] + ',';
                dataStr += "}";
                if (data) {
                    dataStr = dataStr.substring(0, dataStr.length - 1) + "," + data + "}";
                }               
                var url = '../Service/BusinessService.aspx?Action=Add';
                myMask.show();
                Ext.Ajax.request({
                    method: 'post',
                    url: url,
                    params: { data: dataStr, PlaceType: placeType, PurPose: purPose, PoliceStation: policeStation, Street: street, ResponsibilityArea: responsibilityArea },
                    success: onSuccess,
                    failure: onFailure
                });
                function onFailure(request, options) {
                    myMask.hide();
                    showErrorMessage('操作失败', request.responseText, '');
                }
                function onSuccess(request, options) {
                    // 服务器返回json形式的结果
                    myMask.hide();
                    var reText = request.responseText;
                    var reTextObj = Ext.util.JSON.decode(reText);
                    if (eval(reTextObj.success)) {
                        showMessage('操作成功', '保存成功');
                        if (grid)
                            updata(grid);
                        if (fn)
                            fn.call(this, reText);
                        if (sender)
                            sender.close();
                    } else {
                        showErrorMessage('操作失败', reTextObj.message, '');
                    }
                }

            }
        };
    </script>
</head>
<body>
    <div id="bf_div">
    </div>
</body>
</html>
